package com.ruoyi.develop.goodsSaleMaterialDetail.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsSaleMaterialDetail.domain.GoodsSaleMaterialDetail;
import com.ruoyi.develop.goodsSaleMaterialDetail.service.IGoodsSaleMaterialDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售产品物料选用明细Controller
 * @author qh
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/goodsSaleMaterialDetail/goodsSaleMaterialDetail")
public class GoodsSaleMaterialDetailController extends BaseController {
    @Autowired
    private IGoodsSaleMaterialDetailService goodsSaleMaterialDetailService;

    /**
     * 查询销售产品物料选用明细列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSaleMaterialDetail entity) {
        startPage();
        List<GoodsSaleMaterialDetail> list = goodsSaleMaterialDetailService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出销售产品物料选用明细列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:export')")
    @Log(title = "销售产品物料选用明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSaleMaterialDetail entity) {
        List<GoodsSaleMaterialDetail> list = goodsSaleMaterialDetailService.selectList(entity);
        ExcelUtil<GoodsSaleMaterialDetail> util = new ExcelUtil<GoodsSaleMaterialDetail>(GoodsSaleMaterialDetail. class);
        util.exportExcel(response, list, "销售产品物料选用明细数据");
    }

    /**
     * 获取销售产品物料选用明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsSaleMaterialDetailService.selectById(id));
    }

    /**
     * 新增销售产品物料选用明细
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:add')")
    @Log(title = "销售产品物料选用明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.insert(entity));
    }

    /**
     * 修改销售产品物料选用明细
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:edit')")
    @Log(title = "销售产品物料选用明细", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.update(entity));
    }

    /**
     * 删除销售产品物料选用明细
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialDetail:remove')")
    @Log(title = "销售产品物料选用明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsSaleMaterialDetailService.deleteByIds(ids));
    }

    @Log(title = "销售产品物料选用提交添加", businessType = BusinessType.INSERT)
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submit(entity));
    }

    @Log(title = "销售产品物料选用提交添加", businessType = BusinessType.INSERT)
    @PostMapping("/submitSale")
    public AjaxResult submitSale(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submitSale(entity));
    }

    @Log(title = "销售产品锁定提交添加", businessType = BusinessType.INSERT)
    @PostMapping("/submitGoodsSale")
    public AjaxResult submitGoodsSale(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submitGoodsSale(entity));
    }

    @Log(title = "发货销售产品关联入库", businessType = BusinessType.INSERT)
    @PostMapping("/submitGoodsSaleFahuo")
    public AjaxResult submitGoodsSaleFahuo(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submitGoodsSaleFahuo(entity));
    }

    @Log(title = "其他出入库产品物料选用提交添加", businessType = BusinessType.INSERT)
    @PostMapping("/submitOther")
    public AjaxResult submitOther(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submitOther(entity));
    }

    @Log(title = "领料单产品物料选用提交添加", businessType = BusinessType.INSERT)
    @PostMapping("/submitMain")
    public AjaxResult submitMain(@RequestBody GoodsSaleMaterialDetail entity) {
        return toAjax(goodsSaleMaterialDetailService.submitMain(entity));
    }
}
